Temporal Dead Zone
Variables declared with var are hoisted at the top of their function scope. It means they are initialized with undefined even before the code execution reaches the declaration.
However, variables declared with let and const are also hoisted but they are not initialized. Instead, they are placed in the Temporal Dead Zone from the start ot the block until the declaration is encountered.
TDZ refers to the period during which a variable is in scope but cannot be accessed because it has not been initialized.
var variable allocate memory in global window object but let and const memory allocate memory in script object which is why it handle differntly and value is not initialized. you can access var variable within window object(window.variable_name) but you can't access let, const variable except their name.
console.log(x);
console.log(y); // ReferenceError
var x = 5;
let y = 6;